    package com.example.administrator.meishi;

import android.content.Intent;
import android.content.SharedPreferences;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import android.widget.Toast;

import com.example.administrator.meishi.bean.MyUser;

import java.util.List;

import cn.bmob.sms.BmobSMS;
import cn.bmob.v3.BmobQuery;
import cn.bmob.v3.BmobUser;
import cn.bmob.v3.exception.BmobException;
import cn.bmob.v3.listener.FindListener;
import cn.bmob.v3.listener.LogInListener;
import cn.bmob.v3.listener.SaveListener;

public class Activity2 extends AppCompatActivity {
    //用户登录操作
    private EditText et_yh;
    private EditText et_ma;
    private Button btn;
    private SharedPreferences sp;
    private TextView tv;

    @Override
    protected void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_2);
        BmobSMS.initialize(this, "7168d73ba6ec89a9c83df9bac9fb2d19");
        initView();
        tv.setOnClickListener(new View.OnClickListener(){
            @Override
            public void onClick(View v) {
                Intent intent=new Intent(Activity2.this,Activity3.class);
                startActivity(intent);

            }
        });

    }

    private void initView() {
        et_yh = (EditText) this.findViewById(R.id.et_yh);
        et_ma = (EditText) this.findViewById(R.id.et_ma);
        btn = (Button) this.findViewById(R.id.btn_dl);
        tv = (TextView) findViewById(R.id.tv_zc);
        btn.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String name = et_yh.getText().toString();
                String mima = et_ma.getText().toString();
                BmobUser.loginByAccount(name, mima, new LogInListener<MyUser>() {
                    @Override
                    public void done(MyUser myUser, BmobException e) {
                        if (e==null){
                            Toast.makeText(Activity2.this, "登录成功", Toast.LENGTH_SHORT).show();
                            Intent intent1 = new Intent(Activity2.this,MainActivity.class);
                                  startActivity(intent1);
                        }else {
                            Toast.makeText(Activity2.this, "登录失败", Toast.LENGTH_SHORT).show();
                        }
                    }
                });
            }
        });

    }


//                mBtLogin.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        String username = mEtUsername.getText().toString().trim();
//                        String password = mEtPassWord.getText().toString().trim();
//
//                        BmobUser.loginByAccount(username, password, new LogInListener<MyUser>() {
//                            @Override
//                            public void done(MyUser myUser, BmobException e) {
//                                if(e==null){
//                                    Toast.makeText(UserLogin.this, "登录成功", Toast.LENGTH_SHORT).show();
//                                    Intent intent1 = new Intent(UserLogin.this,MainActivity.class);
//
//                                    startActivity(intent1);
//                                }else {
//                                    Toast.makeText(UserLogin.this, "登录失败", Toast.LENGTH_SHORT).show();
//                                }
//                            }
//                        });
//                    }
//                });

        }

